package com.itheima.app.controller;

import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {

    @Autowired
    private SettingManager settingManager;
    //用户通用设置 - 读取
    @GetMapping("/users/settings")
    public ResponseEntity findSettings(){
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!");

        return settingManager.findSettings();
    }

    /**
     * 设置陌生人问题 - 保存
     * 请求方式是post  请求的数据为json 必须要使用@RequestBody接受
     * 请求方式是get  String字符串接收即可
     */
    @PostMapping("/users/questions")
    public ResponseEntity saveOrUpdateQuestions(@RequestBody Map<String,String> map){
        String content = map.get("content");

        return settingManager.saveOrUpdateQuestions(content);
    }


    //通知设置 - 保存
    @PostMapping("/users/notifications/setting")
    public ResponseEntity saveOrUpdateNotifications(@RequestBody Notification notification){


        return settingManager.saveOrUpdateNotifications(notification);
    }

    //@RequestParam(defaultValue = "5")   Integer pagesize 获得浏览器参数 如果传递参数没有才使用默认值
    //app端默认传递的参数就是10  key 就是pagesize 前端使用的是小写
    //黑名单 - 翻页列表
    @GetMapping("/users/blacklist")
    public ResponseEntity findBlackList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "5") Integer pagesize
    ){

       // pagesize = 2;
        return settingManager.findBlackList(page , pagesize);
    }


    //删除黑名单
    @DeleteMapping("/users/blacklist/{blackUserId}")
    public ResponseEntity deleteBlackList(@PathVariable Long blackUserId){


        return settingManager.deleteBlackList(blackUserId);
    }

}
